﻿CREATE PROCEDURE [acms].[Post_GetAllBySiteIdAndParentPath]
	@SiteId int, 
	@ParentPath varchar(255),
	@SiteVersion DateTime
AS

	declare @tmp DateTime

	set @tmp = acms.GetPublishDate(@SiteId, @SiteVersion)
	
	if(@tmp is null and @SiteVersion is not null)
		return 0
	
	if not Right(@ParentPath, 1) = '/'
		set @ParentPath = @ParentPath + '/'

	SELECT a.*, b.ParentPath, b.PublishDate as SiteVersion
	FROM [Post_View] a
		inner join [PostPositions] b on a.Id = b.PostId and isnull(b.PublishDate, '9999/12/31') = isnull(@tmp, '9999/12/31')
	Where SiteId = @SiteId
		and b.ParentPath = @ParentPath
	ORDER By Sequence
RETURN 0;